// pages/mine/mine.js
const $api = require("../../api/mine").API
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentData: 0, 
    selectPerson: true,
    userinfo:wx.getStorageSync('child'),
    classinfo:wx.getStorageSync('classinfo')
  },
//页面信息加载
  onShow(){
    var t = this
    t.setData({
      userinfo:wx.getStorageSync('child'),
      classinfo:wx.getStorageSync('classinfo')
    })
  },
  //跳转添加孩子页面
  add:function(){
    wx.navigateTo({
      url:'/pages/mine/baby/add'
    })
  },
  //跳转邀请家人页面
  yaoqing:function(){
    wx.navigateTo({
      url: '/pages/mine/yaoqing/yaoqing',
      success: (result)=>{
        
      },
      fail: ()=>{},
      complete: ()=>{}
    });
  },
  //跳转每日食谱页面
  food:function(){
    wx.navigateTo({
      url: '/pages/mine/food/food',
      success: (result)=>{
        
      },
      fail: ()=>{},
      complete: ()=>{}
    });
  },

  bindchange: function(e) {
    const that = this;
    that.setData({
      currentData: e.detail.current
    })
  },
  //点击切换，滑块index赋值
  checkCurrent: function(e) {
    const that = this;

    if (that.data.currentData === e.target.dataset.current) {
      return false;
    } else {

      that.setData({
        currentData: e.target.dataset.current
      })
    }
  },
  //跳转到任务中心
  gototasklist(e){
    var t =this
    wx.navigateTo({
      url: '/pages/mine/tasklist/index',
    })
  },
  // 跳转到我的积分
  gotointegral(e){
    var t = this
    wx.navigateTo({
      url:'/pages/mine/integral/index'
    })
  },
  //跳转到我的课程
  gotomycourse(e){
    var t = this
    wx.navigateTo({
      url:'/pages/mine/mycourse/index'
    })
  },
  //跳转到我的设置
  gotosetting(e){
    var t = this
    wx.navigateTo({
      url:'/pages/mine/setlists/index'
    })
  },
  // 轮播图切换
  childchange(e){
    var t= this
    console.log(e.detail.current)
    t.setData({
      currentData: e.detail.current
    })
    t.choosechild()
  },
  choosechild(){
    var t = this
    wx.setStorageSync('childinfo', t.data.userinfo[t.data.currentData])
    var data = {
        child_id:wx.getStorageSync('childinfo').child_id
      }
    $api.getClass(data).then(res=>{
        wx.setStorageSync('classinfo', res.data[0])
      t.setData({
        classinfo:res.data[0]
      })
    })
  },
})